package com.kmdd.xtds

import android.app.Activity
import android.app.Application
import android.widget.Toast
import com.kmdd.xtds.configs.PrefsManager
import com.kmdd.xtds.room.BloodPressureDatabase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MyApp : Application() {

    override fun onCreate() {
        super.onCreate()

        PrefsManager.load(this)
        initDao()
    }

    private fun initDao() {
        CoroutineScope(Dispatchers.Main).launch {
            withContext(Dispatchers.IO) {
                BloodPressureDatabase.getInstance(this@MyApp)
            }
        }
//        GlobalScope.launch(Dispatchers.IO) {
//
//        }
    }

}

fun Activity.toast(msg: String) {
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}